import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * Code taken from following URL
 * http://www.artima.com/forums/flat.jsp?forum=1&thread=36883
 * @author Administrator
 *
 *Lance Staley also helped with creation of the socket.
 *
 */

public class ClientSideSocket {

	String ip = null;
	int port = 0;
	String key = null;
	
	public ClientSideSocket(String i, int p, String k){
		ip = i;
		port = p;
		key = k;
	}
	
	public void makeSocket(){
		JFrame frame = new JFrame();
		Socket socket = null;
		DataOutputStream os = null;
			try {
				socket = new Socket(this.ip, this.port);
				os = new DataOutputStream(socket.getOutputStream());
				
			} catch (UnknownHostException e) {
				JOptionPane.showMessageDialog(frame, "Host not found");
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		if(socket != null){
			try {
				os.writeBytes(this.key);
				os.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		ReceiveFile rec = new ReceiveFile(socket);
		rec.makeSocket();
	}
}
